<template>
  <div class="app-container">
    <div class="app-containermain">
      <div class="fontsize" style="margin-top: 30px">钉钉的配置</div>
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="100px"
        style="width: 100%"
      >
        <p class="fontsize">公司配置</p>

        <div class="flexdiv" prop="fsiteNo">
          <div class="fontw">*企业ID</div>
          <div>
            <el-input
              readonly
              unselectable="on"
              v-model="dataForm.fsiteNo"
              style="width: 500px !important"
              required="true"
            />
          </div>
        </div>
        <!-- <el-form-item label="*appid" prop="appid" style="width: 100%;color: red;">
          <el-input v-model="dataForm.appid" style="width: 300px!important;" />
        </el-form-item> -->
        <p class="fontsize">应用配置</p>
        <p class="fontsize">通讯录</p>

        <div class="flexdiv" prop="selfAppAgentid">
          <div class="fontw">自建应用Agentld</div>
          <div>
            <el-input
              v-model="dataForm.selfappAgentid"
              style="width: 500px !important"
            />
          </div>
        </div>

        <p class="fontsize">自建应用</p>

        <div class="flexdiv" prop="selfAppAppid">
          <div class="fontw">自建应用Appid</div>
          <div>
            <el-input
              v-model="dataForm.selfappAppid"
              style="width: 500px !important"
            />
          </div>
        </div>
        <div class="flexdiv" prop="selfAppSecret">
          <div class="fontw">自建应用Secret</div>
          <div>
            <el-input
              v-model="dataForm.selfappSecret"
              style="width: 500px !important"
            />
          </div>
        </div>
      </el-form>

      <div style="text-align: center; margin-top: 50px">
        <el-button
          style="width: 100px; background: #f56c6c; color: white"
          @click="cancel"
          >清空</el-button
        >
        <el-button style="width: 100px" type="primary" @click="change"
          >确定</el-button
        >
      </div>
    </div>
  </div>
</template>
  
  <style scoped>
.app-containermain {
  width: 750px;
  margin: 0 auto;
}
.fontsize {
  font-weight: 600;
  font-size: 18px;
  margin: 20px 0;
}
.flexdiv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  letter-spacing: 1px;
}
.fontw {
  width: 150px;
  margin-right: 5px;
  margin-left: 80px;
  color: red;
}
</style>
  <script>
import { sysauthinfo } from "@/api/notificationmanagement";
import { dingdingConfigcreate, dingdingConfiglist } from "@/api/dingConfig";

export default {
  name: "ChangePassword",
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入内容"));
      } else {
        callback();
      }
    };
    return {
      fsiteNo: this.$store.state.user.fsiteNo,
      dataForm: {},
      rules: {
        fsiteNo: [
          { required: true, message: "fsiteNo不能为空", trigger: "blur" },
        ],
        agentid: [
          { required: true, message: "agentid不能为空", trigger: "blur" },
          { validator: validatePass, trigger: "blur" },
        ],
        selfAppAppid: [
          { required: true, message: "selfAppAppid不能为空", trigger: "blur" },
          { validator: validatePass, trigger: "blur" },
        ],
        selfAppSecret: [
          { required: true, message: "selfAppSecret不能为空", trigger: "blur" },
          { validator: validatePass, trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getlist();
  },
  methods: {
    getlist() {
      var newjson = {};

      console.log("内存数据", this.$store.state.user);
      newjson.fsiteNo = this.fsiteNo;

      dingdingConfiglist(newjson).then((res) => {
        let arr = res.data.data.list;
        this.dataForm = arr[0];
      });
    },

    //点击按钮清空内容
    cancel() {
      (this.dataForm.fsiteNo = ""), (this.dataForm.selfappAgentid = "");
      this.dataForm.selfappAppid = "";
      this.dataForm.selfappSecret = "";
      this.$message("清空成功");
    },

    //点击按钮确定提交内容
    change() {
      if (
        this.dataForm.fsiteNo != "" &&
        this.dataForm.selfappAgentid != "" &&
        this.dataForm.selfappAppid != "" &&
        this.dataForm.selfappSecret != ""
      ) {
        dingdingConfigcreate(this.dataForm).then((res) => {
          console.log("chenggong", res);
          this.dataForm = res.data.data;
        });
        this.$message({
          message: "数据保存成功",
          type: "success",
        });
      } else {
        this.$message("数据不能为空");
      }
    },
  },
};
</script>
  